package Practice;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Random;

//MouseListener---鼠标事件
public class MyJFrame2 extends JFrame implements MouseListener {
    //创建按钮
    JButton jtb1=new JButton("点我啊");

    public MyJFrame2(){
        //界面设置
        this.setSize(603,680);
        //设置界面标题
        this.setTitle("拼图单机版 V1.0");
        //设置游戏置顶
        this.setAlwaysOnTop(true);
        //设置界面居中
        this.setLocationRelativeTo(null);
        //设置游戏关闭模式
        this.setDefaultCloseOperation(3);
        //取消默认居中
        this.setLayout(null);

        //设置按钮大小
        jtb1.setBounds(0,0,100,50);
        //给按钮绑定addMouseListener事件
        jtb1.addMouseListener(this);

        //将按钮添加到界面当中
        this.getContentPane().add(jtb1);

        //整个界面显示出来
        this.setVisible(true);
    }
    //单击
    @Override
    public void mouseClicked(MouseEvent e) {
        System.out.println("单击");
    }
    //按下不松
    @Override
    public void mousePressed(MouseEvent e) {
        System.out.println("按下不松");
    }
    //松开
    @Override
    public void mouseReleased(MouseEvent e) {
        System.out.println("松开");
    }
    //划入
    @Override
    public void mouseEntered(MouseEvent e) {
        System.out.println("划入");
    }
    //划出
    @Override
    public void mouseExited(MouseEvent e) {
        System.out.println("划出");
    }
}
